package com.bestcem.xm.ticket.service.dto.ticket.rule;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.bestcem.xm.ticket.entity.mongo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.List;

/**
 * mq查询工单中的条件
 * 历史遗漏问题:当时由于实体类接收不到我需要的数据，就建立这个实体类用于映射
 * 现在可以接收数据了，但是由于牵扯过多，所以移动到dto里
 *
 * @author jy.zhao
 * @version 1.0
 * @date 2021/8/23 10:27
 **/
@EqualsAndHashCode(callSuper = true)
@Data
public class TicketRuleCondition extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 7775296702937244867L;
    /**
     * 问卷id
     */
    private String surveyId;

    /**
     * 工单配置id
     */
    private String ticketConfigId;

    /**
     * 规则标题
     */
    private String title;

    /**
     * 同一问卷内，规则id唯一
     */
    private Integer gid;

    /**
     * 二次投放任务，工单完成或失败状态
     */
    private Integer operation;

    /**
     * 创建人
     */
    private String creator;

    /**
     * 版本号
     */
    private Integer version;

    /**
     * 规则类型
     *
     * @see com.bestcem.xm.ticket.enums.TicketRuleTypeEnum
     */
    private Integer type;

    /**
     * 工单生成条件
     * 字段类型，需要确认具体字段
     */
    private Condition condition;

    @Data
    public static class Condition implements Serializable {


        private static final long serialVersionUID = -9149967409648997250L;
        private Integer logic;

        private List<JSONObject> filters;

        private Integer ruleType;

        private String rule;

        /**
         * 条件名称
         */
        @JSONField(name = "trigger_name")
        private String triggerName;

        @Data
        public static class Filter implements Serializable {

            private static final long serialVersionUID = -2817195630850474692L;
            /**
             * 题目类型
             */
            private Integer operation;

            private Integer category;

            private String value;

            private List<String> sourceQ;

        }
    }
}
